package com.mz.ozy.adapter;

import android.text.TextUtils;
import android.widget.ImageView;

import androidx.annotation.Nullable;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.mz.ozy.R;
import com.mz.ozy.bean.VirtualOrderBean;
import com.mz.ozy.utils.Utils;
import com.mz.ozy.utils.glideUtils.GlideUtils;

import org.jetbrains.annotations.NotNull;

import java.util.List;

/**
 * Created by Administrator on 2018/11/20.
 */

public class VirtualOrderAdapter extends BaseQuickAdapter<VirtualOrderBean, BaseViewHolder> {

    public VirtualOrderAdapter(@Nullable List<VirtualOrderBean> data) {
        super(R.layout.view_item_submit_order, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, VirtualOrderBean item) {
        ImageView ivIcon = helper.getView(R.id.iv_only_goods_icon);
        String img_zt = "";
        if (!TextUtils.isEmpty(item.getImg_zt())) {
            final String[] splitImgZt = item.getImg_zt().split(",");
            if (splitImgZt.length > 0) {
                img_zt = splitImgZt[0];
            }
        }
        GlideUtils.loadRoundImg(mContext, ivIcon, img_zt, R.mipmap.default_foods_icon, 4);
        if (!TextUtils.isEmpty(item.getTradname())) {
            helper.setText(R.id.tv_only_goods_title, item.getTradname());
        } else {
            helper.setText(R.id.tv_only_goods_title, item.getProductName());
        }
        helper.setText(R.id.tv_only_goods_info, item.getGname());
        helper.setText(R.id.tv_goods_price, getPrice(item));
        helper.setText(R.id.tv_count, "×" + item.getNum());
    }

    @NotNull
    private String getPrice(VirtualOrderBean item) {
        String price = "";
        if (!TextUtils.isEmpty(item.getPrice()) && Double.parseDouble(item.getPrice()) != 0.00) {
            price += "¥";
            price += Utils.decimalUtils(item.getPrice(), 2);
        }
        if (!TextUtils.isEmpty(item.getMarketPrice()) && Double.parseDouble(item.getMarketPrice()) != 0.00) {
            if (!TextUtils.isEmpty(price)) {
                price += "+";
                price += Utils.decimalUtils(item.getMarketPrice(), 2);
                price += "积分";
            } else {
                price += Utils.decimalUtils(item.getMarketPrice(), 2);
                price += "积分";
            }
        }
        if (TextUtils.isEmpty(price)) {
            price = "¥0.00";
        }
        return price;
    }
}
